<template>
<div>
   <div class="g_top_box">
		<div class="g_right_box"></div> 
		<div class="g_left_box"><h4>管理员信息</h4></div>
	</div>
	<div class="g_content_box">

		<Form :model="info" label-position="left" :label-width="100">
			<FormItem label="账号">
				{{info.username}}
			</FormItem>
			<FormItem label="最后登录时间">
				{{info.last_login}}
			</FormItem>
			<FormItem label="角色">
				<Select v-model="info.role_id" style="width:200px">
					<Option v-for="item in role_list" :value="item.id" :key="item.id">{{ item.name }}</Option>
				</Select>
			</FormItem>
			<FormItem label="名称">
				<Input v-model="info.nickname" style="width:200px;"></Input>
			</FormItem>
			
			<FormItem>
				<Button type="primary" @click="save">修改</Button>
			</FormItem>
		</Form>

		 
		<Card :bordered="false">
            <p slot="title">修改密码</p>
            <div>
				<Form :model="info" label-position="left" :label-width="100">
					
					<FormItem label="密码">
						<Input v-model="info.password" type="password" style="width:200px;"></Input>
					</FormItem>
					<FormItem label="再次确认密码">
						<Input v-model="info.confirm_password"  type="password" style="width:200px;"></Input>
					</FormItem>
					<FormItem>
						<Button type="primary" @click="change_password">确认</Button>
					</FormItem>
				</Form>
			
			</div>
        </Card>
		
	</div>
</div>
</template>

<script>
import Wcore from '@/libs/common';
export default {
    name: 'admin_info',
    data (){
		
        return {
            info:{
				role_id:0,
				nickname:''
			},
			id:0,
			role_list:[]
        };
    },
	created(){

		this.id = this.$route.params.id;
		this.load_data();
		this.load_roles();
		
		this.$emit('change','admin');
	},
    computed: {
       
    },
	methods:{
		load_roles(){
			var self = this;
			var postdata = {
				id:this.id
			};
			Whttp.load('System/Role/get_all',postdata,function(result){
				self.role_list = result;
			});
		},
		load_data(){
			var self = this;
			var postdata = {
				id:this.id
			};
			Whttp.load('Admin/Admin/get_info',postdata,function(result){
				self.info = result;
			});
		},
		save(){
			var self = this;
			var postdata = {
				id:this.id,
				nickname:this.info.nickname,
				role_id:this.info.role_id
			};
			Whttp.load('Admin/Admin/save',postdata,function(result){
				self.$Message.info('保存成功');
				self.$router.back();
			});
		},
		change_password(){
			if(!confirm('是否修改密码')){
				return ;
			}
			var self = this;
			var postdata = {
				id:this.id,
				password:this.info.password,
				confirm_password:this.info.confirm_password
			};
			Whttp.load('Admin/Admin/change_password',postdata,function(result){
				self.$Message.info('修改成功');
			});
		}
	}
};
</script>